﻿@model CustomerForumSubscriptionsModel

@using SmartStore.Web;
@using SmartStore.Web.Models.Customer;
@using SmartStore.Web.Framework.UI;

@{    
	Html.AddTitleParts(T("PageTitle.ForumSubscriptions").Text);

	Layout = "_MyAccount";
	ViewBag.PageClassToken = "forumsubscriptions";
	ViewBag.PageTitle = T("Account.ForumSubscriptions").Text;
}

@if (Model.ForumSubscriptions.Count == 0)
{
	<div class="alert alert-warning">
		@T("Account.ForumSubscriptions.NoSubscriptions")
	</div>
	return;
}

<div class="alert alert-success mb-0">
    @T("Account.ForumSubscriptions.Description")
</div>

@using (Html.BeginForm())
{
	<div class="subscription-list">
		<div class="table-responsive">
			<table class="table">
				<thead>
					<tr>
						<th style="width: 30px">
							<input type="checkbox" id="selectall" />
						</th>
						<th>
							@T("Account.ForumSubscriptions.InfoColumn")
						</th>
					</tr>
				</thead>
				<tbody>
					@for (int i = 0; i < Model.ForumSubscriptions.Count; i++)
				{
					var item = Model.ForumSubscriptions[i];
						<tr>
							<td style="width: 30px">
								<input type="checkbox" name="fs@(item.Id)" class="rowcheckbox" />
							</td>
							<td dir="auto">
								@if (item.TopicSubscription)
								{
									@Html.RouteLink(item.Title, "TopicSlug", new { Id = item.ForumTopicId, slug = item.Slug })
								}
								else
								{
									@Html.RouteLink(item.Title, "ForumSlug", new { Id = item.ForumId, slug = item.Slug })
								}
							</td>
						</tr>
				}
				</tbody>
			</table>
		</div>
		
		@if (Model.TotalPages > 1)
		{
			@Html.SmartStore().Pager(Model).Name("paginator").QueryParam("page")
		}
                
		<div class="buttons">
			<button class="btn btn-danger btn-lg" type="submit" value="delete-subs">
				@T("Account.ForumSubscriptions.DeleteSelected")
			</button>
		</div>
	</div>
}

<script>
    $(function () {
    	$('#selectall').on('click', function (e) {
    		$('.subscription-list .rowcheckbox').attr('checked', $(this).is(':checked')).change();
    	});

    	$(document).on('change', '.subscription-list .rowcheckbox', function (e) {
    		var numChkBoxes = $('.subscription-list .rowcheckbox').length;
    		var numChkBoxesChecked = $('.subscription-list .rowcheckbox:checked').length;
    		$('#selectall').attr('checked', numChkBoxes == numChkBoxesChecked && numChkBoxes > 0);
    	});
    });
</script>
